//
//  VerifyWordsVC.m
//  ShandsMod
//
//  Created by zh s on 2023/3/21.
//  Copyright © 2023 zh_s. All rights reserved.
//

#import "VerifyWordsVC.h"
#import "HelpWordsModel.h"

@interface VerifyWordsVC ()<GWGoodsListViewDelegate>
/**! GWGoodsListView *tagList*/
@property (nonatomic, strong) GWGoodsListView *chooseTagV;
/**! GWGoodsListView *tagList*/
@property (nonatomic, strong) GWGoodsListView *allTagV;

/**! _contentArr*/
@property (nonatomic, strong) NSMutableArray *contentArr;


@end

@implementation VerifyWordsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"验证助记词";
    self.nav.backgroundColor = UIColor.clearColor;

    UIView *backV = [[UIView alloc] init];
    [self.view addSubview:backV];
    backV.backgroundColor = UIColor.whiteColor;
    backV.frame = CGRectMake(20, NAV_HEIGHT +20, SCREEN_WIDTH - 40, 240);
    [backV settingShadowOpacity:0.2 withShadowColor:RGB(153, 153, 153) wihtShadowRadius:5 withshadowOffset:CGSizeMake(0, 3)];
    GWRadius(backV, 10);
    
    UIImageView *topImg = [[UIImageView alloc] init];
    [backV addSubview:topImg];
    topImg.image = IMAGE_NAME(@"icon_verifyWords_top");
    [topImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.right.mas_equalTo(backV.mas_right).mas_offset(0);
        make.height.mas_equalTo(50);
    }];
    
    
    
//    UIImageView *explainImg = [[UIImageView alloc] init];
//    [backV addSubview:explainImg];
//    explainImg.image = IMAGE_NAME(@"icon_verifyWords_topExplain");
//    [explainImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(42);
//        make.centerY.mas_equalTo(topImg.mas_centerY);
//        make.width.mas_equalTo(90);
//        make.height.mas_equalTo(16);
//    }];
    
    ///格子
   NSArray *strArray1=@[];
    

    _chooseTagV = [[GWGoodsListView alloc] initWithFrame:CGRectMake(0, 57, SCREEN_WIDTH - 54, 0)];
    _chooseTagV.canDelete = YES;
    _chooseTagV.canTouch = YES;
    [backV addSubview:_chooseTagV];
    [_chooseTagV setMarginBetweenTagLabel:7 AndBottomMargin:7];
    [_chooseTagV setTagWithTagArray:strArray1];
    
    _chooseTagV.delegate = self;
//    tagList.hidden = YES;
//    tagList.hidden = YES;
//    self.goodHeight = tagList.totalHeight +36;
//    [self.mainTableView reloadData];

    
    //提示
    UIImageView *tipsImg = [[UIImageView alloc] init];
    [self.view addSubview:tipsImg];
    tipsImg.image = IMAGE_NAME(@"icon_helpWords_tips");
    [tipsImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(18);
        make.top.mas_equalTo(backV.mas_bottom).mas_offset(17);
        make.width.mas_equalTo(15);
        make.height.mas_equalTo(15);
    }];
    
    UILabel *tipsLab = [BaseViewFactory labelWithFrame:CGRectZero textColor:RGB(253, 193, 72) font:FONT_NAME(FONT_Medium, 13) textAligment:NSTextAlignmentLeft andtext:@"请根据您备份的助记词，按顺序选择填充"];
    [self.view addSubview:tipsLab];
    
    [tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipsImg.mas_right).mas_offset(7);
        make.top.mas_equalTo(backV.mas_bottom).mas_offset(15);
//        make.width.mas_equalTo(SCREEN_WIDTH - 64);
        make.right.mas_equalTo(backV.mas_right);
        make.height.mas_equalTo(15);
    }];
    
    
    ///格子
   NSArray *strArray = @[@"大好人",@"自定义流式标签",@"github",@"code4app",@"已婚",@"阳光开朗",@"慷慨大方帅气身材好",@"仗义",@"值得一交的朋友",@"值得的交",@"值得交的朋友"];
    _contentArr = [NSMutableArray arrayWithCapacity:0];
    for (NSString *name in strArray) {
        HelpWordsModel *model = [[HelpWordsModel alloc] init];
        model.name = name;
        [_contentArr addObject:model];
    }

    _allTagV = [[GWGoodsListView alloc] initWithFrame:CGRectMake(20, NAV_HEIGHT + 300, SCREEN_WIDTH - 40, 0)];
    _allTagV.canTouch = YES;
    _allTagV.btnBackColor = [UIColor whiteColor];
    [self.view addSubview:_allTagV];
    [_allTagV setMarginBetweenTagLabel:7 AndBottomMargin:7];
    [_allTagV setTagWithTagArray:_contentArr];
    WS(weakSelf);
    _allTagV.didselectItemBlock = ^(NSArray * _Nonnull arr) {
//        [weakSelf.chooseTagV setTagWithTagArray:arr];
        [weakSelf updateDataArrWithArr:arr withDeleteModel:nil withIsDelete:NO];
        
        [arr enumerateObjectsUsingBlock:^(HelpWordsModel *chooseObj, NSUInteger idx, BOOL * _Nonnull stop) {
            [weakSelf.contentArr enumerateObjectsUsingBlock:^(HelpWordsModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([chooseObj.name isEqualToString:obj.name]) {
                    obj.isSelected = obj.isSelected;
                }
            }];
        }];
      
    };
    
    UIButton *nextBtn = [BaseViewFactory buttonWithFrame:CGRectZero font:FONT_NAME(FONT_Semibold, 16) title:@"确认" titleColor:UIColor.whiteColor backColor:MAIN_ACTIVE_COLOR];
    [self.view addSubview:nextBtn];
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(35);
        make.top.mas_equalTo(_allTagV.mas_bottom).mas_offset(25);
//        make.top.mas_equalTo(_chooseTagV.mas_bottom).mas_offset(180);
        make.width.mas_equalTo(SCREEN_WIDTH - 70);
        make.height.mas_equalTo(40);
    }];
    GWRadius(nextBtn, 20);
    [nextBtn addTarget:self action:@selector(nextBtnClick) forControlEvents:UIControlEventTouchUpInside];

}

- (void)nextBtnClick {
    
}

#pragma mark ----- 代理
- (void)updateDataArrWithArr:(NSArray *)arr withDeleteModel:(nonnull HelpWordsModel *)deleteModel withIsDelete:(BOOL)isDelete  {
    [_chooseTagV.tagArr removeAllObjects];
    _chooseTagV.totalHeight = 0;
    for (UIView *view in self.chooseTagV.subviews) {
      if ([view isKindOfClass:[UIButton class]] ) {
          [view removeFromSuperview];
      }
    }

    [self.chooseTagV setTagWithTagArray:arr];
    
    
    if (isDelete) {
        [_allTagV.tagArr removeAllObjects];
        
        [self.contentArr enumerateObjectsUsingBlock:^(HelpWordsModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj.name isEqualToString:deleteModel.name]) {
                obj.isSelected = NO;
            }else {
                JTDLog(@"选中的name%@",obj.name);
            }
                    
        }];
        
        for (UIView *view in self.allTagV.subviews) {
          if ([view isKindOfClass:[UIButton class]] ) {
              [view removeFromSuperview];
          }
        }
        self.allTagV.backgroundColor = RandomColor;
        self.allTagV.totalHeight = 0;
        [self.allTagV setTagWithTagArray:self.contentArr];
        
    }
    
}

@end
